package com.sphd.restaurantsystem.activitys.funding;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;

import com.sphd.restaurantsystem.R;
import com.sphd.restaurantsystem.adapters.MyViewPagerAdapter;
import com.sphd.restaurantsystem.base.BaseActivity;
import com.sphd.restaurantsystem.fragments.ApplyForFragment;
import com.sphd.restaurantsystem.info.InvestRuleInfo;
import com.sphd.restaurantsystem.info.RestaurantInfo;
import com.sphd.restaurantsystem.utils.Constant;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 申请记录  “type==1为投资记录界面” type==0为撤资记录界面” type==3为个人申请记录界面”
 * 各种记录
 */
public class ApplyForActivity extends BaseActivity {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tabs)
    TabLayout tabs;
    @BindView(R.id.m_vp)
    ViewPager mVp;
    String[] titles = {"待处理", "已批准", "已驳回"};
    MyViewPagerAdapter myViewPagerAdapter;
    List<Fragment> fragments;
    Intent intent;
    Bundle bundle;
    RestaurantInfo restaurantInfo;
    int type = -1;
    InvestRuleInfo investRuleInfo;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_apply_for);
        ButterKnife.bind(this);
        initView();
        initEvent();
    }

    private void initEvent() {
        toolbar.setNavigationOnClickListener(v -> {setResult(0); finish();});

    }

    private void initView() {
        intent = getIntent();
        bundle = intent.getExtras();
        type = bundle.getInt(Constant.TYPE);
        if (type == 0) {
            setTitleBar(toolbar, "撤资申请");
        } else if (type == 1) {
            setTitleBar(toolbar, "投资申请");
        } else if (type == 3) {
            setTitleBar(toolbar, "申请记录");
        }
        investRuleInfo= (InvestRuleInfo) bundle.getSerializable(Constant.INVESTRULE);
        restaurantInfo = (RestaurantInfo) bundle.getSerializable(Constant.RESTAURANTSINFO);
        fragments = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            ApplyForFragment applyForFragment = new ApplyForFragment();
            applyForFragment.sendDate(restaurantInfo, i, type,investRuleInfo);
            fragments.add(applyForFragment);
        }
        myViewPagerAdapter = new MyViewPagerAdapter(getSupportFragmentManager(), fragments, titles);
        mVp.setAdapter(myViewPagerAdapter);
        tabs.setupWithViewPager(mVp);
    }

}
